package com.rocket.bedroom.utils;

import org.apache.shiro.crypto.hash.Md5Hash;

import java.util.Random;

/**
 * @Author: 周毅
 * @ClassName:
 * @Description: TODO
 * @Date: Create in 22:33 2020/6/10
 * @ModifyBy:
 */
public class SaltUtils
{

    public static String getSalt(int n)
    {
        char[] salt = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!@#$%^&*0987654321".toCharArray();
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < n; i++)
        {
            char c = salt[new Random().nextInt(salt.length)];
            builder.append(c);
        }
        return builder.toString();
    }

    public static void main(String[] args)
    {
        String salt = getSalt(5);
        System.out.println(salt);
        System.out.println("18770958050".substring(11 - 4));

        //md5+salt+hash散列
        Md5Hash msh = new Md5Hash("messi", salt, 1024);
        System.out.println("md5+salt+hash散列：" + msh.toHex());
    }

}
